/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.sentry.protocol;

import io.sentry.IUnknownPropertiesConsumer;
import io.sentry.util.Objects;

import java.util.Map;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * An installed and loaded package as part of the Sentry SDK.
 *
 * @since 2021-06-02
 */
public final class SentryPackage implements IUnknownPropertiesConsumer {
    /**
     * Name of the package.
     */
    private @NotNull String name;
    /**
     * Version of the package.
     */
    private @NotNull String version;

    @SuppressWarnings("unused")
    private @Nullable Map<String, Object> unknown;

    /**
     * constructor
     *
     * @param name name
     * @param version version
     */
    public SentryPackage(final @NotNull String name, final @NotNull String version) {
        this.name = Objects.requireNonNull(name, "name is required.");
        this.version = Objects.requireNonNull(version, "version is required.");
    }

    /**
     * constructor
     *
     * @deprecated <p>Use {@link SentryPackage#SentryPackage(String, String)} instead.
     */
    @Deprecated
    public SentryPackage() {
        this("", "");
    }

    public @NotNull String getName() {
        return name;
    }

    public void setName(final @NotNull String name) {
        this.name = Objects.requireNonNull(name, "name is required.");
    }

    public @NotNull String getVersion() {
        return version;
    }

    public void setVersion(final @NotNull String version) {
        this.version = Objects.requireNonNull(version, "version is required.");
    }

    @ApiStatus.Internal
    @Override
    public void acceptUnknownProperties(final @NotNull Map<String, Object> unknowns) {
        this.unknown = unknowns;
    }
}
